package com.fjnldx.mes.domain.energy.vo;

import java.util.LinkedList;
import java.util.List;

public class SSCXVO {
    /**
     * 每个工序耗电情况
     */
    List<SSCX_GongXu_VO> gongXuHD;

    /**
     * 络筒工序下的品种耗电百分比
     */
    List<SSCX_PJ_VO> luoTongPjHD;

    /**
     * 细沙工序下的品种耗电百分比
     */
    List<SSCX_PJ_VO> xiShaPjHD;

    public List<SSCX_GongXu_VO> getGongXuHD() {
        return gongXuHD;
    }

    public void setGongXuHD(List<SSCX_GongXu_VO> gongXuHD) {

        List<SSCX_GongXu_VO> result = new LinkedList<>();
        //单独计算清花平均耗电
        SSCX_GongXu_VO qingHua = new SSCX_GongXu_VO();
        qingHua.setGongxu("清花");
        for (SSCX_GongXu_VO vo : gongXuHD) {
            if ("多仓".equals(vo.getGongxu()) ||
                    "抓包".equals(vo.getGongxu()) ||
                    "精开".equals(vo.getGongxu())) {
                qingHua.setHd(qingHua.getHd() + vo.getHd());
            }
            result.add(vo);


        }
        result.add(qingHua);


        this.gongXuHD = result;
    }

    public List<SSCX_PJ_VO> getLuoTongPjHD() {
        return luoTongPjHD;
    }

    public void setLuoTongPjHD(List<SSCX_PJ_VO> luoTongPjHD) {
        this.luoTongPjHD = luoTongPjHD;
        getPercent(this.luoTongPjHD);
    }

    public List<SSCX_PJ_VO> getXiShaPjHD() {
        return xiShaPjHD;
    }

    public void setXiShaPjHD(List<SSCX_PJ_VO> xiShaPjHD) {
        this.xiShaPjHD = xiShaPjHD;
        getPercent(this.xiShaPjHD);
    }

    //
    public void getPercent(List<SSCX_PJ_VO> luoTongPjHD) {
        if (null == luoTongPjHD) {
            return;
        }
        double total = luoTongPjHD.stream().mapToDouble(SSCX_PJ_VO::getHd).sum();
        if (total <= 0) {
            return;
        }
        luoTongPjHD.forEach(e -> e.setHd(e.getHd() / total));
    }
}
